home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / editors / eedraw / src / eep / eedepson.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-29  |  5.8 KB  |  189 lines

  1. /*****************************************************************************
  2. *   Program to draw EE diagrams on epson compatible printers.             *
  3. *                                         *
  4. * Written by:  Gershon Elber            IBM PC Ver 1.0,    Oct. 1989    *
  5. *****************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #ifdef __MSDOS__
  11. #include <stdlib.h>
  12. #include <conio.h>
  13. #include <dos.h>
  14. #include <alloc.h>
  15. #include <dir.h>
  16. #endif /* __MSDOS__ */
  17.  
  18. #include "program.h"
  19. #include "config.h"
  20. #include "igraph.h"
  21. #include "eelibs.h"
  22. #include "eeredraw.h"
  23. #include "eeload.h"
  24.  
  25. /* Undef DEBUG_MALLOC_TC20 iff you have TurboC 2.0. It assumes the offset    */
  26. /* part of the pointer is always 8 which is TRUE only of TC 2.0.         */
  27. /* #define DEBUG_MALLOC_TC20  /* Add debugging aid for malloc/free routines. */
  28.  
  29. /* Clipping boundaries of current page size (A4 by default). */
  30. int EEPageSizeX = PAGE_A4_XSIZE * PAGE_SCALER / 2,
  31.     EEPageSizeY = PAGE_A4_YSIZE * PAGE_SCALER / 2;
  32. DrawGenericStruct *EEDrawList = NULL;         /* All objects are saved here. */
  33.  
  34. #ifdef __MSDOS__
  35. static char *VersionStr =
  36.     "EEDEPSON IBMPC "
  37.     EEDRAW_VERSION
  38.     "    Gershon Elber,  "
  39.     __DATE__ ",   " __TIME__ "\n"
  40.     "(C) Copyright 1989 Gershon Elber, Non commercial use only.\n";
  41. #else
  42. static char *VersionStr =
  43.     "EEDEPSON    Unix version 1.2    Gershon Elber,  \n\
  44.     (C) Copyright 1990 Gershon Elber, Non commercial use only.\n";
  45. #endif /* __MSDOS__ */
  46.  
  47. static char *UsageStr =
  48.     "Usage: EEDEpson [-g] [-r] [-1] [-2] [-3] [-d] [-z] EEDrawFile.EED\n";
  49. static char *LoadLibraryList = NULL;
  50. static ConfigStruct SetUp[] =
  51. {
  52.     { "Libraries",    (VoidPtr) &LoadLibraryList,    SU_STRING_TYPE },
  53. };
  54. #define NUM_SET_UP    (sizeof(SetUp) / sizeof(ConfigStruct))
  55.  
  56. #ifdef __MSDOS__
  57. extern unsigned int _stklen = 32766;         /* Increase default stack size. */
  58. #endif /* __MSDOS__ */
  59.  
  60. /*****************************************************************************
  61. * Main routine - Read Parameter    line and do what you need...             *
  62. *****************************************************************************/
  63. void main(int argc, char **argv)
  64. {
  65.     int i = 1, DoubleDensity = FALSE, GifOutput = FALSE, RowOutput = FALSE,
  66.     DirectPrint = 0;
  67.     char FullName[LINE_LEN_SHORT];
  68.     FILE *f;
  69.  
  70.     while (i < argc) {
  71.     if (strcmp(argv[i], "-z") == 0) {
  72.         fprintf(stderr, "%s%s", UsageStr, VersionStr);
  73.         MyExit(-1);
  74.     }
  75.     else if (strcmp(argv[i], "-d") == 0)
  76.         DoubleDensity = TRUE;
  77.     else if (strcmp(argv[i], "-g") == 0)
  78.         GifOutput = TRUE;
  79.     else if (strcmp(argv[i], "-r") == 0)
  80.         RowOutput = TRUE;
  81.     else if (strcmp(argv[i], "-1") == 0)
  82.         DirectPrint = 1;
  83.     else if (strcmp(argv[i], "-2") == 0)
  84.         DirectPrint = 2;
  85.     else if (strcmp(argv[i], "-3") == 0)
  86.         DirectPrint = 3;
  87.     else if (i + 1 != argc || argv[i][0] == '-')
  88.         FatalError(UsageStr);
  89.  
  90.     i++;
  91.     }
  92.  
  93.     if (argv[i - 1][0] == '-' || argc == 1) {
  94.     fprintf(stderr, UsageStr);
  95.     FatalError("No EED file specified.\n");
  96.     }
  97.  
  98.     if ((f = fopen(argv[i - 1], "rt")) == NULL) {
  99.     strcpy(FullName, argv[i - 1]);
  100.     strcat(FullName, FILE_EXTENSION);
  101.     if ((f = fopen(FullName, "rt")) == NULL) {
  102.         fprintf(stderr, UsageStr);
  103.         FatalError("Failed to open EED file");
  104.     }
  105.     }
  106.  
  107.     Config("eedepson", SetUp, NUM_SET_UP);   /* Read config. file if exists. */
  108.  
  109.     IGInitGraph();                 /* Initiate the graphic driver. */
  110.  
  111.     if (LoadLibraryList != NULL) {
  112.     LoadLibraries(LoadLibraryList);
  113.     free(LoadLibraryList);
  114.     LoadLibraryList = NULL;
  115.     }
  116.  
  117.     LoadEEFile(f);
  118.     fclose(f);
  119.     RedrawAllScreen();
  120.  
  121.     if (GifOutput)
  122.     IGDumpScreen(OUTPUT_GIF, DirectPrint, DoubleDensity);
  123.     else if (RowOutput)
  124.     IGDumpScreen(OUTPUT_RAW, DirectPrint, DoubleDensity);
  125.     else {
  126.     IGDumpScreen(OUTPUT_EPSON, DirectPrint, DoubleDensity);
  127.     }
  128.  
  129.     MyExit(0);
  130. }
  131.  
  132. /*****************************************************************************
  133. * My Routine to    allocate dynamic memory. All program requests must call this *
  134. * routine (no direct call to malloc). Dies if no memory.             *
  135. *****************************************************************************/
  136. VoidPtr MyMalloc(unsigned size)
  137. {
  138.     VoidPtr p;
  139.  
  140.     p = malloc(size);
  141.     if (p == NULL)
  142.     FatalError("Not enough memory, exit\n");
  143.  
  144. #ifdef DEBUG_MALLOC_TC20
  145.     if (FP_OFF(p) != 8)
  146.     FatalError("Bogus pointer detected. This should be reported.\n");
  147. #endif /* DEBUG_MALLOC_TC20 */
  148.  
  149.     return p;
  150. }
  151.  
  152. /*****************************************************************************
  153. * My Routine to    free dynamic memory. All program requests must call this     *
  154. * routine (no direct call free).                         *
  155. *****************************************************************************/
  156. void MyFree(VoidPtr p)
  157. {
  158. #ifdef DEBUG_MALLOC_TC20
  159.     if (FP_OFF(p) != 8)
  160.     FatalError("Bogus pointer detected. This should be reported.\n");
  161. #endif /* DEBUG_MALLOC_TC20 */
  162.  
  163.     free(p);
  164. }
  165.  
  166. /*****************************************************************************
  167. * MyExit routine. Note it might call to CloseGraph without calling         *
  168. * InitGraph(), or call MouseClose() without MouseInit() etc. and it is the   *
  169. * responsibility of the individual modules to do nothing in these cases.     *
  170. *****************************************************************************/
  171. void MyExit(int ExitCode)
  172. {
  173.     IGCloseGraph();                /* Close the graphic driver. */
  174.  
  175.     exit(ExitCode);
  176. }
  177.  
  178. /*****************************************************************************
  179. * Same as MyExit routine, but print error message to stderr.             *
  180. *****************************************************************************/
  181. void FatalError(char *ErrMsg)
  182. {
  183.     IGCloseGraph();                /* Close the graphic driver. */
  184.  
  185.     fprintf(stderr, "EEDRAW: %s\n", ErrMsg);
  186.  
  187.     exit('F');
  188. }
  189.